<template>
  <div class="head-image" @click="showUserInfo($event)">
    <div class="avatar"
         :style="{backgroundImage: `url(${url})`,'background-size':'100%',width: size+'px',height: size+'px',cursor: 'pointer'}">
    </div>
<!--    <img :src="url" :style="{width: size+'px',height: size+'px',cursor: 'pointer'}"/>-->
    <slot></slot>
  </div>
</template>

<script>

import httpRequest from "@/api/httpRequest";

export default {
  name: "headImage",
  data() {
    return {}
  },
  props: {
    id: {
      type: String
    },
    size: {
      type: Number,
      default: 50
    },
    url: {
      type: String
    }
  },
  methods: {
    showUserInfo(e) {
      if (this.id && this.id > 0) {
        httpRequest({
          url: `/user/find/${this.id}`,
          method: 'get'
        }).then((user) => {
          this.$store.commit("setUserInfoBoxPos", e);
          this.$store.commit("showUserInfoBox", user);
        })
      }
    }
  }
}
</script>

<style scoped lang="less">
.head-image {
  //.three-artile-right {
  //  width: 122px;
  //  height: 91px;
  //  opacity: 1;
  //  border-radius: 5px;
  //  background-repeat: no-repeat;
  //  background-position: center;
  //  background-size: cover;
  //}

  position: relative;

  img {
    position: relative;
    overflow: hidden;
    border-radius: 5%;
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
  }

  img:before {
    content: '';
    display: block;
    width: 100%;
    height: 100%;
    background: url('../../../assets/logo.png') no-repeat 0 0;
    background-size: 100%;
  }
}
</style>
